<!-- 添加经营主体 -->
<template>
	<div>
		<subForm :formInline="formInline" :formItem="formItem" @changePicker="changePicker" @getFiles="getFiles"></subForm>
	</div>
</template>

<script>
	import subForm from "../../components/current/vForm.vue";
	import areaData from '../../static/js/city.four.js'

	export default {
		components: {
			subForm
		},
		data() {
			return {
				//表格参数
				formItem: [{
					type: 'uploadFile',
					fileType: 'faces',
					label: "头像",
					icon: true,
					clumn: 'faces'
				}, {
					type: 'input',
					label: "经营主体",
					placeholder: "请输入经营主体",
					clumn: 'subName'
				}, {
					type: 'picker',
					pickerType: '',
					label: "身份类型",
					placeholder: "请选择身份类型",
					array: ['第一个', '第二个', '第三个'],
					index: "",
					clumn: 'type'
				}, {
					type: 'picker',
					pickerType: 'multiSelector',
					label: "所在地区",
					labelPosition:'top',
					placeholder: "请选择所在地区",
					multiArray: areaData,
					multiIndex: [0, 0, 0, 0],
					clumn: 'area'
				},
				{
					type: 'input',
					label: "详细地址",
					placeholder: "请输入详细地址", 
					clumn: 'address'
				}, {
					type: 'input',
					label: "负责人姓名",
					placeholder: "请输入姓名",
					clumn: 'name'
				}, {
					type: 'input',
					label: "负责人电话",
					inputType:'number',
					placeholder: "请输入电话",
					clumn: 'phone'
				}],
				//表单字段数据
				formInline: {
					faces: ['/static/images/icons/icon_yuangong.svg'],
					subName: '',
					type: '',
					area: '',
					address:'',
					name: '',
					phone: ''
				},
			}
		},

		methods: {
			// 选择器发生改变时
			changePicker(i, clumn, value) {
				let item = this.formItem[i];
				// 普通选择器赋值
				if (item.pickerType == '' || item.pickerType == 'selector') {
					this.formInline[clumn] = item.array[value];
					return
				}
				//时间选择器赋值
				if (item.pickerType == 'date') {
					this.formInline[clumn] = value;
					console.log("-------" + this.formInline[clumn])
					return
				}
				
				//多列选择器赋值（省-市-区-街道四级联动）
				if (value[0] != item.multiIndex[0]) { //第一列改变时后面的列重置
					value[1] = 0;
					value[2] = 0;
					value[3] = 0;
				}
				if (value[1] != item.multiIndex[1]) { //第二列改变时后面的列重置
					value[2] = 0;
					value[3] = 0;
				}
				if (value[2] != item.multiIndex[2]) { //第二列改变时后面的列重置
					value[3] = 0;
				}
				if (item.pickerType == 'multiSelector') {
					item.multiIndex = value;
					let firstCol = item.multiArray[item.multiIndex[0]];
					let secondCol = firstCol.children[item.multiIndex[1]];
					let thirdCol = secondCol.children[item.multiIndex[2]];
					let fourCol = thirdCol.children[item.multiIndex[3]];
					this.formInline[clumn] = firstCol.name + "-" + secondCol.name + "-" + thirdCol.name + "-" + fourCol.name;
					return
				}
				
				/* //picker-view 选择器赋值（省-市-区-街道四级）
				if (item.pickerType == 'region') {
					item.multiIndex = value;
					let firstCol = item.multiArray[item.multiIndex[0]];
					this.formInline[clumn] = firstCol.name;
					return
				} */
			},
			
			/* regionConfirm(formindex,index){
				console.log(formindex)
				console.log(index)
				let multiIndex = this.formItem[formindex].multiIndex[0];
				console.log(this.formItem[formindex].multiArray[multiIndex].children)
				// if(this.formItem[formindex].multiArray[index].children){
					
				// }
				// this.formItem.splice(formindex+1, 0, {
				// 	type: 'picker',
				// 	pickerType: 'region',
				// 	label: "",
				// 	placeholder: "请选择所在市",
				// 	index:1,
				// 	multiArray: this.formItem[formindex].multiArray[index].children,
				// 	multiIndex: [0],
				// 	clumn: 'shi'
				// });
			}, */

			// 接收上传图片路径并赋值
			getFiles(i, clumn, value) {
				this.formInline[clumn] = value;
			}
		}
	}
</script>

<style>
	.form-title {
		padding: 0 5%;
		color: rgb(136, 136, 136);
		line-height: 60rpx;
	}
</style>
